

package com.hazelcast.sql.impl.state;

import com.hazelcast.sql.SqlRow;
import com.hazelcast.sql.impl.AbstractSqlResult;
import com.hazelcast.sql.impl.QueryId;
import com.hazelcast.sql.impl.ResultIterator;

import java.util.UUID;

public class QueryClientState {

    private final UUID clientId;
    private final QueryId queryId;
    private final AbstractSqlResult sqlResult;
    private final boolean closed;
    private final long createdAt;

    private ResultIterator<SqlRow> iterator;

    public QueryClientState(UUID clientId, QueryId queryId, AbstractSqlResult sqlResult, boolean closed) {
        this.clientId = clientId;
        this.queryId = queryId;
        this.sqlResult = sqlResult;
        this.closed = closed;

        createdAt = System.nanoTime();
    }

    public UUID getClientId() {
        return clientId;
    }

    public QueryId getQueryId() {
        return queryId;
    }

    public AbstractSqlResult getSqlResult() {
        return sqlResult;
    }

    public boolean isClosed() {
        return closed;
    }

    public long getCreatedAtNano() {
        return createdAt;
    }

    public ResultIterator<SqlRow> getIterator() {
        assert sqlResult != null;

        if (iterator == null) {
            iterator = sqlResult.iterator();
        }

        return iterator;
    }
}
